package org.example.common.core.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo;
import org.example.common.core.domain.Result;
import org.example.common.core.domain.ResultTable;

import java.util.List;

public class BaseController {

    public Result<Void> toResult(int rows) {
        return rows > 0 ? Result.ok() : Result.fail();
    }

    public Result<Void> toResult(boolean result) {
        return result ? Result.ok() : Result.fail();
    }

    public ResultTable getTable(List<?> list) {
        if (CollectionUtil.isEmpty(list)) {
            return ResultTable.empty();
        }
        long total = new PageInfo<>(list).getTotal();     // 获取符合查询条件的数据总数
        return ResultTable.success(list, total);
    }

}
